<template>
  <div class="table-box">
    <div class="operation-box">
      <div class="input-box">
        所属路线：
        <el-input
          v-model="search"
          placeholder="请输入关键字"
          class="input__item"
        />
        <el-button type="danger">查询</el-button>
      </div>

      <div class="add-box">
        <el-button type="primary" @click="dialogVisible = true">
          <el-icon><CirclePlus /></el-icon>
          添加杆塔
        </el-button>
      </div>
    </div>

    <el-table
      :data="tableData"
      stripe
      border
      table-layout="auto"
      style="max-width: 80vw"
    >
      <el-table-column prop="id" label="杆塔编号" />
      <el-table-column prop="route" label="所属路线" />
      <el-table-column prop="state" label="状态（启用/未启用）">
        <template #default> 停用 </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">
            停用
          </el-button>
          <el-button
            size="small"
            type="primary"
            @click="handleDelete(scope.$index, scope.row)"
          >
            修改
          </el-button>
          <el-button size="small" type="danger"> 删除 </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      v-model="dialogVisible"
      title="添加杆塔"
      width="500"
      align-center
    >
      <el-form label-width="auto" :model="[]" style="width: 400px">
        <el-form-item label="杆塔编号">
          <el-input />
        </el-form-item>
        <el-form-item label="所属路线">
          <el-input />
        </el-form-item>
        <el-form-item label="启用状态">
          <el-radio-group v-model="search">
            <el-radio border value="Sponsor">启用</el-radio>
            <el-radio border value="Venue">不启用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="dialogVisible = false">
            确认
          </el-button>
          <el-button type="primary" @click="dialogVisible = false">
            取消
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

interface User {
  date: string;
  name: string;
  address: string;
}

const search = ref("");
const dialogVisible = ref(false);

const tableData = [
  {
    id: "XW00001",
    route: "西渭线",
    state: false,
  },
  {
    id: "XW00002",
    route: "西渭线",
    state: false,
  },
  {
    id: "XW00003",
    route: "西渭线",
    state: false,
  },
  {
    id: "XW00004",
    route: "西渭线",
    state: false,
  },
];

const handleEdit = (index: number, row: User) => {
  console.log(index, row);
};

const handleDelete = (index: number, row: User) => {
  console.log(index, row);
};
</script>

<style scoped>
.table-box {
  width: 1000px;
  margin: 0 auto;
}

.operation-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.input-box {
  color: #747070;
  font-size: 14px;
}

.input__item {
  width: 250px;
  margin: 10px;
}
</style>
